package domain.domain;

import java.util.ArrayList;
import java.util.Scanner;

public class Studentxuan {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<Student>();
        getStudent(list);
        getStudent(list);
        getStudent(list);
        getStudent(list);
        ArrayList<Student> ls=xuanze(list);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).show();
        }
        System.out.println(ls);
    }

    public static ArrayList<Student> xuanze(ArrayList<Student> list) {
        ArrayList<Student> ls = new ArrayList<Student>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getAge() < 18) {
                ls.add(list.get(i));
            }
        }
        return ls;
    }

    private static void getStudent(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第" + (list.size() + 1) + "个学生姓名:");
        String stu1name = sc.next();
        System.out.println("请输入第" + (list.size() + 1) + "个学生年龄:");
        int stu1age = sc.nextInt();
        Student stu = new Student(stu1name, stu1age);
        list.add(stu);
        return;
    }


}
